import java.util.regex.Pattern
import java.util.regex.Matcher

//Pattern operator 模式操作符 
// 在 /  / 中的\的不需要转义,在"" ''需要转义
def p = ~/\wfoo/
assert p instanceof Pattern

//Find operator 查找操作符
def text = "mata some text  to matb"
def m = text =~ /mat(a|b)/                                           
assert m instanceof Matcher      
if(m) println "ok 1" //与Perl中的=~一样。当m出现在if while中时表示 m.find()
m.each{
	println it
}

//Match operator匹配操作符
res = text ==~ /(match) .+ \1/
if(res) println "ok 2"


def saying = "Now is the time for all good men (and women) to come to the aid of their country"
def pattern = ~/(\w+en)/
def matcher = pattern.matcher(saying)
def count = matcher.getCount()
println "Matches = $count"
for(i in 0..<count) {
    println matcher[i]
}


